//
//  XMLExhibitorShowModel.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/15.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XMLExhibitorShowModel.h"
#import "XXTool.h"

@implementation XMLExhibitorShowModel

+(void)requestVisitorCollectExihibitorListWithCompletion:(void (^)(BOOL, NSMutableArray<RXMLExhibitorInformationModel *> *))block
{
    [DKHTTPRequest sendDataWithShortUrl:@"favorites_visitor"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     NSMutableArray *list =[NSMutableArray array];
                                     if ([[serverDic objectForKey:@"total"] intValue]!=0)
                                     {
                                         NSString *realmSearchString = @"";
                                         NSArray *tempArray = [serverDic objectForKey:@"exlist"];
                                         for (NSDictionary *temp in tempArray)
                                         {
                                             realmSearchString = [NSString stringWithFormat:@"%@OR ExhibitorID = '%@'",realmSearchString,[temp objectForKey:@"exhibitor_id"]];
                                         }
                                         realmSearchString = [realmSearchString substringFromIndex:2];
                                         
                                         RLMResults *resluts = [RXMLExhibitorInformationModel objectsInRealm:[RLMRealm realmWithPath:[XXTool dataBasePath]] where:realmSearchString];
                                         for (RXMLExhibitorInformationModel * temp in resluts)
                                         {
                                             [list addObject:temp];
                                         }
                                     }
                                     block(YES,list);
                                 }
                                 else
                                 {
                                     block(NO,nil);
                                 }
                                 return YES;
                             } IsBuffering:YES
                      IsNeedReplaceWrap:NO
                        IsUseUpLoadHead:NO];
}

@end
